# -*- coding: utf-8 -*-
__author__ = 'lztkdr'
__date__ = '2020/3/30 9:13'

"""
条形图应用场景：
    数据统计
    频率(占比)统计（市场饱和度）

"""

from matplotlib import pyplot as plt

# 如果要显示中文标题和坐标表示，需要添加以下两行代码
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# 票房统计：
# http://58921.com/alltime/2017
# http://www.endata.com.cn/BoxOffice/

"""
假设你获取到了2017年内地电影票房前20的电影(列表a)和电影票房数据(列表b),那么如何更加直观的展示该数据?

a = ["战狼2","速度与激情8","功夫瑜伽","西游伏妖篇","变形金刚5：最后的骑士","摔跤吧！爸爸","加勒比海盗5：死无对证","金刚：骷髅岛","极限特工：终极回归","生化危机6：终章","乘风破浪","神偷奶爸3","智取威虎山","大闹天竺","金刚狼3：殊死一战","蜘蛛侠：英雄归来","悟空传","银河护卫队2","情圣","新木乃伊",]

b=[56.01,26.94,17.53,16.49,15.45,12.96,11.8,11.61,11.28,11.12,10.49,10.3,8.75,7.55,7.32,6.99,6.88,6.86,6.58,6.23] 单位:亿


"""

# 带 \n 的 电影名称
x = ["战狼2", "速度与激情8", "功夫瑜伽", "西游伏妖篇", "变形金刚5：\n最后的骑士", "摔跤吧！\n爸爸", "加勒比海盗5：\n死无对证", "金刚：骷髅岛", "极限特工：\n终极回归",
     "生化危机6：\n终章", "乘风破浪", "神偷奶爸3", "智取威虎山", "大闹天竺", "金刚狼3：\n殊死一战", "蜘蛛侠：\n英雄归来", "悟空传", "银河护卫队2", "情圣", "新木乃伊", ]
y = [56.01, 26.94, 17.53, 16.49, 15.45, 12.96, 11.8, 11.61, 11.28, 11.12, 10.49, 10.3, 8.75, 7.55, 7.32, 6.99, 6.88,
     6.86, 6.58, 6.23]

x2 = ["战狼2", "速度与激情8", "功夫瑜伽", "西游伏妖篇", "变形金刚5：最后的骑士", "摔跤吧！爸爸", "加勒比海盗5：死无对证", "金刚：骷髅岛", "极限特工：终极回归", "生化危机6：终章",
      "乘风破浪", "神偷奶爸3", "智取威虎山", "大闹天竺", "金刚狼3：殊死一战", "蜘蛛侠：英雄归来", "悟空传", "银河护卫队2", "情圣", "新木乃伊", ]

plt.figure(figsize=(25, 20), dpi=80)

# bar 时，width 条形粗细，默认0.8
# plt.bar(x, y, width=0.2)
# plt.xticks(x, rotation=45)
# plt.xlabel("电影名称")
# plt.ylabel("票房/单位:亿")

# 当底部文字太长时，可以使用 横向条状图
# barh 时，height 条形粗细，默认0.8
plt.barh(x2, y, height=0.2, color='orange')
plt.yticks(x2)
plt.ylabel("电影名称")
plt.xlabel("票房/单位:亿")

plt.grid(alpha=0.2)

plt.show()
